package heven.holt.wan.android.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import heven.holt.library.base.BaseFragment
import heven.holt.wan.android.adapter.NavigationSystemAdapter
import heven.holt.wan.android.databinding.FragmentNavigationSystemBinding
import heven.holt.wan.android.viewmodel.NavigationViewModel

@AndroidEntryPoint
class NavigationSystemFragment : BaseFragment<FragmentNavigationSystemBinding>() {
    private val navigationViewModel: NavigationViewModel by viewModels()

    override fun bindViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): FragmentNavigationSystemBinding =
        FragmentNavigationSystemBinding.inflate(inflater, container, false)

    override fun initView() {
        binding.recyclerView.itemAnimator = null
    }

    override fun initData() {
        navigationViewModel.navigationProjectSystemListLiveData.observe(viewLifecycleOwner) { projectList ->
            binding.recyclerView.adapter = NavigationSystemAdapter(projectList)
        }

        if (navigationViewModel.navigationProjectSystemListLiveData.value == null) {
            navigationViewModel.requestProjectSystemList()
        }
    }
}